import { http } from '@/server'

/** 获取开班审核详情数据 */
export const fetchClassAuditDetail = async (id: number) => {
    try {
        const { data } = await http.get(`/country/group/info/${id}`)
        return data
    } catch (error) {
        return undefined
    }
}

/**
 * 开班审核 - 通过
 * @param {number} 培训计划id
 */
export const approveClass = async (
    id: number,
    params: {
        plan_group_id: string
        check_reason?: string
        check_image: string
        check_image_name: string
    },
) => {
    return await http.post(`/country/group/check/${id}`, {
        ...params,
        check: 1,
    })
}

/**
 * 开班审核 - 驳回
 * @param {number} 培训计划id
 * @param {reason} 意见
 */
export const rejectClass = async (id: number, reason: string) => {
    return await http.post(`/country/group/check/${id}`, {
        check: 2,
        check_reason: reason,
    })
}

/**
 * 获取培训计划
 * @param {number} gid 班级id
 */
export const fetchTrainPlan = async (gid: number) => {
    try {
        const { data } = await http.get<string[] | Record<number, string>>(
            `/country/group/group-plan/${gid}`,
        )
        return data
    } catch (error) {
        return []
    }
}
